package semant;

import util.ClassTreeNode;
import util.ErrorHandler;
import visitor.Visitor;

public abstract class SemanticVisitor extends Visitor {
	
	static ClassTreeNode objectNode;
	
	public boolean reservedNameChecker(String name){
		return (name.equals("this") || name.equals("super") || name.equals("null") ? true : false);		
	}
	static void setObjectNode(ClassTreeNode node) {
		objectNode = node;
	}
	
	static boolean methodExists(String object, String method) {
		return (getMethod(object,method) == null) ? false : true;
	}
	static Object getMethod(String object, String method) {
		ClassTreeNode ctnode = objectNode.lookupClass(object);
		String  s = null;
		while(ctnode != null && s == null) {
			s = (String)ctnode.getMethodSymbolTable().peek(method);
			ctnode = ctnode.getParent();
		}
		return s;
	}
	static ClassTreeNode getClassNode(String clazz) {
		return objectNode.lookupClass(clazz);
	}
	
	
}
